package io.iamting93.code.controller;

import io.iamting93.code.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author boting.guo
 * @date 2021/11/30 13:57
 */

@RestController
public class CodeController {

    @Autowired
    private CodeService codeService;

    @GetMapping("/create/{email}")
    public boolean createCode(@PathVariable("email") String emailAddress) {
        return codeService.refreshCode(emailAddress);
    }

    @GetMapping("/validate/{email}/{code}")
    public int validateCode(@PathVariable("email") String emailAddress,
                            @PathVariable("code") String code) {
        return codeService.validateCode(emailAddress, code);
    }
}
